//
//  AOStatusRetweetView.swift
//  weibo_zha
//
//  Created by _zha on 16/10/28.
//  Copyright © 2016年 渣. All rights reserved.
//

import UIKit
///转发微博
class AOStatusRetweetView: UIView {
    
    var retweetViewCons: Constraint?
    
    // 定义属性 供外界赋值
    var statusViewModel: AOStatusViewModel?{
        didSet{
            // 转发正文
            contentLabel.text = statusViewModel?.retweetContentText
            //卸载约束
            retweetViewCons?.uninstall()
            //
            if (statusViewModel?.statusModel?.retweeted_status?.pic_urls?.count)! > 0 {
                pictureView.picUrls = statusViewModel?.statusModel?.retweeted_status?.pic_urls
                pictureView.isHidden = false
                
                self.snp_makeConstraints(closure: { (make) in
                    self.retweetViewCons = make.bottom.equalTo(pictureView).offset(10).constraint
                })
            }else{
                pictureView.isHidden = true
                
                self.snp_makeConstraints(closure: { (make) in
                    self.retweetViewCons = make.bottom.equalTo(contentLabel).offset(10).constraint
                })
            }
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - 设置视图
    private func setupUI(){
        backgroundColor = UIColor(white: 237/255, alpha: 1)
        // 01 添加控件
        addSubview(contentLabel)
        addSubview(pictureView)
        // 02 添加约束
        contentLabel.snp_makeConstraints { (make) in
            make.top.left.equalTo(10)
        }
        
        pictureView.snp_makeConstraints { (make) in
//            make.size.equalTo(CGSize(width: 100, height: 100))
            make.left.equalTo(contentLabel)
            make.top.equalTo(contentLabel.snp_bottom).offset(10)
        }
        
        self.snp_makeConstraints { (make) in
            self.retweetViewCons = make.bottom.equalTo(pictureView).offset(10).constraint
        }
    }
    
    // MARK: - 懒加载控件
    // 转发正文
    private lazy var contentLabel: UILabel = UILabel(textColor: UIColor.darkGray, fontSize: AONormalFontSize, text: "设置视图设置视图设置视图设置视图设置视图设置视图设置视图设置视图设置视图设置视图设置视图设置视图设置视图设置视图设置视图", maxWidth: AOScreeW - 20)
    private lazy var pictureView: AOStatusPictrueView = {
        let view = AOStatusPictrueView()
        view.backgroundColor = self.backgroundColor
        return view
    }()
}
